package com.edu.study.base.stuQuestionRelation.controller;

import com.edu.study.base.stuQuestionRelation.domain.StuQuestionRelationRy;
import com.edu.study.base.stuQuestionRelation.service.IStuQuestionRelationRyService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 题库关系Controller
 *
 * @author jjt
 * @date 2021-02-27
 */
@RestController
@RequestMapping("/stu/questionRelation")
public class StuQuestionRelationRyController extends BaseController
{
    @Autowired
    private IStuQuestionRelationRyService stuQuestionRelationRyService;

    /**
     * 查询题库关系列表
     */
    @PreAuthorize("@ss.hasPermi('stu:questionRelation:list')")
    @GetMapping("/list")
    public TableDataInfo list(StuQuestionRelationRy stuQuestionRelationRy)
    {
        startPage();
        List<StuQuestionRelationRy> list = stuQuestionRelationRyService.selectStuQuestionRelationRyList(stuQuestionRelationRy);
        return getDataTable(list);
    }



    /**
     * 导出题库关系列表
     */
    @PreAuthorize("@ss.hasPermi('stu:questionRelation:export')")
    @Log(title = "题库关系", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(StuQuestionRelationRy stuQuestionRelationRy)
    {
        List<StuQuestionRelationRy> list = stuQuestionRelationRyService.selectStuQuestionRelationRyList(stuQuestionRelationRy);
        ExcelUtil<StuQuestionRelationRy> util = new ExcelUtil<StuQuestionRelationRy>(StuQuestionRelationRy.class);
        return util.exportExcel(list, "questionRelation");
    }

    /**
     * 获取题库关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('stu:questionRelation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(stuQuestionRelationRyService.selectStuQuestionRelationRyById(id));
    }

    /**
     * 新增题库关系
     */
    @PreAuthorize("@ss.hasPermi('stu:questionRelation:add')")
    @Log(title = "题库关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StuQuestionRelationRy stuQuestionRelationRy)
    {
        return toAjax(stuQuestionRelationRyService.insertStuQuestionRelationRy(stuQuestionRelationRy));
    }

    /**
     * 修改题库关系
     */
    @PreAuthorize("@ss.hasPermi('stu:questionRelation:edit')")
    @Log(title = "题库关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StuQuestionRelationRy stuQuestionRelationRy)
    {
        return toAjax(stuQuestionRelationRyService.updateStuQuestionRelationRy(stuQuestionRelationRy));
    }

    /**
     * 删除题库关系
     */
    @PreAuthorize("@ss.hasPermi('stu:questionRelation:remove')")
    @Log(title = "题库关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(stuQuestionRelationRyService.deleteStuQuestionRelationRyByIds(ids));
    }
}
